/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistence;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
 * This class is a JPA entity and is used to represent a user
 * as it will be stored in the database
 * 
 * @author Amigos do Noddy
 *
 */
@Entity
@Table(name = "UTILIZADOR", schema = "APP")
//@NamedQueries({@NamedQuery(name = "Utilizador.findByRefidperson", query = "SELECT u FROM Utilizador u WHERE u.refidperson = :refidperson"), @NamedQuery(name = "Utilizador.findByCode", query = "SELECT u FROM Utilizador u WHERE u.code = :code"), @NamedQuery(name = "Utilizador.findByValid", query = "SELECT u FROM Utilizador u WHERE u.valid = :valid")})
@PrimaryKeyJoinColumn(name = "REFIDPERSON", referencedColumnName = "IDPERSON")
@DiscriminatorValue("Utilizador")
public class Utilizador extends Person implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /*@Id
    @Column(name = "REFIDPERSON", nullable = false)
    private Integer refidperson;*/
    @Column(name = "CODE", nullable = false)
    private int code;
    @Column(name = "VALID", nullable = false)
    private short valid;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "refidpersonUtilizador")
    private Collection<Ticket> ticketCollection;
    
    /*@OneToMany(cascade = CascadeType.ALL, mappedBy = "refidpersonAuthor")
    private Collection<Comment> commentCollection;*/
    
    
    /*@JoinColumn(name = "REFIDPERSON", referencedColumnName = "IDPERSON", insertable = false, updatable = false)
    @OneToOne
    private Person person;*/

    /**
     * Defaut constructor
     */
    public Utilizador() {
    }

    /*public Utilizador(Integer refidperson) {
        this.refidperson = refidperson;
    }*/

    /**
     * Class constructor
     * @param code user activation code
     * @param valid valid state
     */
    public Utilizador(/*Integer refidperson,*/ int code, short valid) {
        //this.refidperson = refidperson;
        this.code = code;
        this.valid = valid;
    }

    /*public Integer getRefidperson() {
        return refidperson;
    }*/

    /*public void setRefidperson(Integer refidperson) {
        this.refidperson = refidperson;
    }*/

    /**
     * Gets the activation code of this user
     */
    public int getCode() {
        return code;
    }

    /**
     * Sets the activation code of this user
     * @param code activation code
     */
    public void setCode(int code) {
        this.code = code;
    }

    /**
     * Checks if this user is valid
     * @return valid status
     */
    public short getValid() {
        return valid;
    }

    /**
     * Sets if this user is valid
     * @param valid valid status
     */
    public void setValid(short valid) {
        this.valid = valid;
    }

    /**
     * Gets the list of tickets
     * @return list of tickets
     */
    public Collection<Ticket> getTicketCollection() {
        return ticketCollection;
    }

    /**
     * Sets the list of tickets
     * @return list of tickets
     * @param ticketCollection
     */
    public void setTicketCollection(Collection<Ticket> ticketCollection) {
        this.ticketCollection = ticketCollection;
    }

    /*public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }*/

    /*@Override
    public int hashCode() {
        int hash = 0;
        hash += (refidperson != null ? refidperson.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Utilizador)) {
            return false;
        }
        Utilizador other = (Utilizador) object;
        if ((this.refidperson == null && other.refidperson != null) || (this.refidperson != null && !this.refidperson.equals(other.refidperson))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.Utilizador[refidperson=" + refidperson + "]";
    }*/

}
